Skip to content

Conversation

@joshheald
Copy link
Contributor

Description

This PR creates or connects to the local catalog database when the POS tab is shown.

  1. Added the database manager to the ServiceLocator using similar pattern as Core Data
  2. Accessing the GRDBManager from POSTabCoordinator if the feature flag is enabled
  3. Log schema

Steps to reproduce

  1. Launch the app and log in
  2. Observe that Started GRDBManager with database path: /var/mobile/Containers/Data/Application/8A3E77E9-E527-4D74-87E5-15F91E5DA427/Documents/woo-local.db is logged, along with the schema

Repeat with pointOfSaleLocalCatalogi1 feature flag set to false – observe those are not logged.

Testing information

Screenshots

image
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@joshheald joshheald added this to the 23.2 milestone Aug 28, 2025
@joshheald joshheald requested a review from jaclync August 28, 2025 15:11
@joshheald joshheald added type: task An internally driven task. status: feature-flagged Behind a feature flag. Milestone is not strongly held. feature: POS labels Aug 28, 2025
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Aug 28, 2025

App Icon📲 You can test the changes from this Pull Request in WooCommerce iOS Prototype by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS Prototype
Build Numberpr16054-9790bd8
Version23.1
Bundle IDcom.automattic.alpha.woocommerce
Commit9790bd8
Installation URL45g5rqhdgttco
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

Copy link
Contributor

@jaclync jaclync left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tested both feature flag states and it worked as expected :shipit:

self.databasePath = databasePath
public final class GRDBManager: GRDBManagerProtocol {

public var databaseConnection: GRDBDatabaseConnection
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could this be let? do we plan to change the connection once it's initialized?

Comment on lines -19 to +20
self.databaseQueue = try DatabaseQueue(path: databasePath)
self.databaseConnection = try DatabaseQueue(path: databasePath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, is this renaming to make it more flexible if we ever decide to switch to DatabasePool?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and to make it mockable – the protocol requirement is DatabaseReader & DatabaseWriter, which both DatabasePool and DatabaseQueue implement. GRDB refers to them as database connections for the general case.


guard let grdbManager = _grdbManager else {
do {
let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe we can fatalError with a custom message instead of direct crashing from implicitly unwrapping with !

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, good point


/// Local SQLite Database Name
///
static let localSQLiteDatabaseName = "woo-local.db"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: any reasons not to use the *.sqlite extension as in the example in the doc? might we want to name it like WooCommerce-local just to be more consistent with the existing sqlite files from Core Data?

I was still able to open the database in DataGrip with woo-local.db in the directory, so just a non-blocking question.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I'd put more thought into the name than the extension. .sqlite is more descriptive, let's use that.

We could go to WooCommerce-local – I didn't, in order to put a bit more space between the Core Data name and the GRDB name. But I'm not holding that view super strongly. I'll leave it as it is for now, but if you feel strongly just let me know and I'll change it 😊

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 👍

@joshheald joshheald enabled auto-merge August 29, 2025 09:36
@joshheald joshheald force-pushed the woomob-1087-woo-poslocal-catalog-create-database-when-the-app-starts branch from 8371993 to 9790bd8 Compare August 29, 2025 09:39
@joshheald joshheald merged commit ee4814f into trunk Aug 29, 2025
14 checks passed
@joshheald joshheald deleted the woomob-1087-woo-poslocal-catalog-create-database-when-the-app-starts branch August 29, 2025 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: POS status: feature-flagged Behind a feature flag. Milestone is not strongly held. type: task An internally driven task.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants